package cesdentalrecord.dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;


/**
 * This class was autogenerated by Torque on:
 *
 * [Mon Mar 22 12:41:25 CST 2010]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Student
 */
public abstract class BaseStudent extends BaseObject
{
    /** The Peer class */
    private static final StudentPeer peer =
        new StudentPeer();

        
    /** The value for the studentID field */
    private int studentID;
      
    /** The value for the surname field */
    private String surname;
      
    /** The value for the firstname field */
    private String firstname;
      
    /** The value for the mi field */
    private String mi;
      
    /** The value for the grade field */
    private String grade;
      
    /** The value for the gender field */
    private String gender;
      
    /** The value for the section field */
    private String section;
      
    /** The value for the birthmonth field */
    private String birthmonth;
      
    /** The value for the birthdate field */
    private String birthdate;
      
    /** The value for the birthyear field */
    private String birthyear;
      
    /** The value for the birthplace field */
    private String birthplace;
      
    /** The value for the age field */
    private int age;
      
    /** The value for the address field */
    private String address;
      
    /** The value for the parent field */
    private String parent;
      
    /** The value for the occupation field */
    private String occupation;
      
    /** The value for the medicalhist field */
    private String medicalhist;
  
    
    /**
     * Get the StudentID
     *
     * @return int
     */
    public int getStudentID()
    {
        return studentID;
    }

                                              
    /**
     * Set the value of StudentID
     *
     * @param v new value
     */
    public void setStudentID(int v) throws TorqueException
    {
    
                  if (this.studentID != v)
              {
            this.studentID = v;
            setModified(true);
        }
    
          
                                  
        // update associated InitialHealthCond
        if (collInitialHealthConds != null)
        {
            for (int i = 0; i < collInitialHealthConds.size(); i++)
            {
                ((InitialHealthCond) collInitialHealthConds.get(i))
                    .setStudentID(v);
            }
        }
                                          
        // update associated OralHealthService
        if (collOralHealthServices != null)
        {
            for (int i = 0; i < collOralHealthServices.size(); i++)
            {
                ((OralHealthService) collOralHealthServices.get(i))
                    .setStudentID(v);
            }
        }
                                          
        // update associated DmfxCond
        if (collDmfxConds != null)
        {
            for (int i = 0; i < collDmfxConds.size(); i++)
            {
                ((DmfxCond) collDmfxConds.get(i))
                    .setStudentID(v);
            }
        }
                                          
        // update associated Total
        if (collTotals != null)
        {
            for (int i = 0; i < collTotals.size(); i++)
            {
                ((Total) collTotals.get(i))
                    .setStudentID(v);
            }
        }
                      }
  
    /**
     * Get the Surname
     *
     * @return String
     */
    public String getSurname()
    {
        return surname;
    }

                        
    /**
     * Set the value of Surname
     *
     * @param v new value
     */
    public void setSurname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.surname, v))
              {
            this.surname = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Firstname
     *
     * @return String
     */
    public String getFirstname()
    {
        return firstname;
    }

                        
    /**
     * Set the value of Firstname
     *
     * @param v new value
     */
    public void setFirstname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.firstname, v))
              {
            this.firstname = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Mi
     *
     * @return String
     */
    public String getMi()
    {
        return mi;
    }

                        
    /**
     * Set the value of Mi
     *
     * @param v new value
     */
    public void setMi(String v) 
    {
    
                  if (!ObjectUtils.equals(this.mi, v))
              {
            this.mi = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Grade
     *
     * @return String
     */
    public String getGrade()
    {
        return grade;
    }

                        
    /**
     * Set the value of Grade
     *
     * @param v new value
     */
    public void setGrade(String v) 
    {
    
                  if (!ObjectUtils.equals(this.grade, v))
              {
            this.grade = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Gender
     *
     * @return String
     */
    public String getGender()
    {
        return gender;
    }

                        
    /**
     * Set the value of Gender
     *
     * @param v new value
     */
    public void setGender(String v) 
    {
    
                  if (!ObjectUtils.equals(this.gender, v))
              {
            this.gender = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Section
     *
     * @return String
     */
    public String getSection()
    {
        return section;
    }

                        
    /**
     * Set the value of Section
     *
     * @param v new value
     */
    public void setSection(String v) 
    {
    
                  if (!ObjectUtils.equals(this.section, v))
              {
            this.section = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Birthmonth
     *
     * @return String
     */
    public String getBirthmonth()
    {
        return birthmonth;
    }

                        
    /**
     * Set the value of Birthmonth
     *
     * @param v new value
     */
    public void setBirthmonth(String v) 
    {
    
                  if (!ObjectUtils.equals(this.birthmonth, v))
              {
            this.birthmonth = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Birthdate
     *
     * @return String
     */
    public String getBirthdate()
    {
        return birthdate;
    }

                        
    /**
     * Set the value of Birthdate
     *
     * @param v new value
     */
    public void setBirthdate(String v) 
    {
    
                  if (!ObjectUtils.equals(this.birthdate, v))
              {
            this.birthdate = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Birthyear
     *
     * @return String
     */
    public String getBirthyear()
    {
        return birthyear;
    }

                        
    /**
     * Set the value of Birthyear
     *
     * @param v new value
     */
    public void setBirthyear(String v) 
    {
    
                  if (!ObjectUtils.equals(this.birthyear, v))
              {
            this.birthyear = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Birthplace
     *
     * @return String
     */
    public String getBirthplace()
    {
        return birthplace;
    }

                        
    /**
     * Set the value of Birthplace
     *
     * @param v new value
     */
    public void setBirthplace(String v) 
    {
    
                  if (!ObjectUtils.equals(this.birthplace, v))
              {
            this.birthplace = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Age
     *
     * @return int
     */
    public int getAge()
    {
        return age;
    }

                        
    /**
     * Set the value of Age
     *
     * @param v new value
     */
    public void setAge(int v) 
    {
    
                  if (this.age != v)
              {
            this.age = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Address
     *
     * @return String
     */
    public String getAddress()
    {
        return address;
    }

                        
    /**
     * Set the value of Address
     *
     * @param v new value
     */
    public void setAddress(String v) 
    {
    
                  if (!ObjectUtils.equals(this.address, v))
              {
            this.address = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Parent
     *
     * @return String
     */
    public String getParent()
    {
        return parent;
    }

                        
    /**
     * Set the value of Parent
     *
     * @param v new value
     */
    public void setParent(String v) 
    {
    
                  if (!ObjectUtils.equals(this.parent, v))
              {
            this.parent = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Occupation
     *
     * @return String
     */
    public String getOccupation()
    {
        return occupation;
    }

                        
    /**
     * Set the value of Occupation
     *
     * @param v new value
     */
    public void setOccupation(String v) 
    {
    
                  if (!ObjectUtils.equals(this.occupation, v))
              {
            this.occupation = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Medicalhist
     *
     * @return String
     */
    public String getMedicalhist()
    {
        return medicalhist;
    }

                        
    /**
     * Set the value of Medicalhist
     *
     * @param v new value
     */
    public void setMedicalhist(String v) 
    {
    
                  if (!ObjectUtils.equals(this.medicalhist, v))
              {
            this.medicalhist = v;
            setModified(true);
        }
    
          
              }
  
         
                                
            
    /**
     * Collection to store aggregation of collInitialHealthConds
     */
    protected List collInitialHealthConds;

    /**
     * Temporary storage of collInitialHealthConds to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initInitialHealthConds()
    {
        if (collInitialHealthConds == null)
        {
            collInitialHealthConds = new ArrayList();
        }
    }

    /**
     * Method called to associate a InitialHealthCond object to this object
     * through the InitialHealthCond foreign key attribute
     *
     * @param l InitialHealthCond
     * @throws TorqueException
     */
    public void addInitialHealthCond(InitialHealthCond l) throws TorqueException
    {
        getInitialHealthConds().add(l);
        l.setStudent((Student) this);
    }

    /**
     * The criteria used to select the current contents of collInitialHealthConds
     */
    private Criteria lastInitialHealthCondsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getInitialHealthConds(new Criteria())
     *
     * @throws TorqueException
     */
    public List getInitialHealthConds() throws TorqueException
    {
        if (collInitialHealthConds == null)
        {
            collInitialHealthConds = getInitialHealthConds(new Criteria(10));
        }
        return collInitialHealthConds;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related InitialHealthConds from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getInitialHealthConds(Criteria criteria) throws TorqueException
    {
        if (collInitialHealthConds == null)
        {
            if (isNew())
            {
               collInitialHealthConds = new ArrayList();
            }
            else
            {
                      criteria.add(InitialHealthCondPeer.STUDENTID, getStudentID() );
                      collInitialHealthConds = InitialHealthCondPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(InitialHealthCondPeer.STUDENTID, getStudentID());
                      if (!lastInitialHealthCondsCriteria.equals(criteria))
                {
                    collInitialHealthConds = InitialHealthCondPeer.doSelect(criteria);
                }
            }
        }
        lastInitialHealthCondsCriteria = criteria;

        return collInitialHealthConds;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getInitialHealthConds(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getInitialHealthConds(Connection con) throws TorqueException
    {
        if (collInitialHealthConds == null)
        {
            collInitialHealthConds = getInitialHealthConds(new Criteria(10), con);
        }
        return collInitialHealthConds;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related InitialHealthConds from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getInitialHealthConds(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collInitialHealthConds == null)
        {
            if (isNew())
            {
               collInitialHealthConds = new ArrayList();
            }
            else
            {
                       criteria.add(InitialHealthCondPeer.STUDENTID, getStudentID());
                       collInitialHealthConds = InitialHealthCondPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(InitialHealthCondPeer.STUDENTID, getStudentID());
                       if (!lastInitialHealthCondsCriteria.equals(criteria))
                 {
                     collInitialHealthConds = InitialHealthCondPeer.doSelect(criteria, con);
                 }
             }
         }
         lastInitialHealthCondsCriteria = criteria;

         return collInitialHealthConds;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student is new, it will return
     * an empty collection; or if this Student has previously
     * been saved, it will retrieve related InitialHealthConds from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Student.
     */
    protected List getInitialHealthCondsJoinStudent(Criteria criteria)
        throws TorqueException
    {
        if (collInitialHealthConds == null)
        {
            if (isNew())
            {
               collInitialHealthConds = new ArrayList();
            }
            else
            {
                            criteria.add(InitialHealthCondPeer.STUDENTID, getStudentID());
                            collInitialHealthConds = InitialHealthCondPeer.doSelectJoinStudent(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(InitialHealthCondPeer.STUDENTID, getStudentID());
                        if (!lastInitialHealthCondsCriteria.equals(criteria))
            {
                collInitialHealthConds = InitialHealthCondPeer.doSelectJoinStudent(criteria);
            }
        }
        lastInitialHealthCondsCriteria = criteria;

        return collInitialHealthConds;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collOralHealthServices
     */
    protected List collOralHealthServices;

    /**
     * Temporary storage of collOralHealthServices to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initOralHealthServices()
    {
        if (collOralHealthServices == null)
        {
            collOralHealthServices = new ArrayList();
        }
    }

    /**
     * Method called to associate a OralHealthService object to this object
     * through the OralHealthService foreign key attribute
     *
     * @param l OralHealthService
     * @throws TorqueException
     */
    public void addOralHealthService(OralHealthService l) throws TorqueException
    {
        getOralHealthServices().add(l);
        l.setStudent((Student) this);
    }

    /**
     * The criteria used to select the current contents of collOralHealthServices
     */
    private Criteria lastOralHealthServicesCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getOralHealthServices(new Criteria())
     *
     * @throws TorqueException
     */
    public List getOralHealthServices() throws TorqueException
    {
        if (collOralHealthServices == null)
        {
            collOralHealthServices = getOralHealthServices(new Criteria(10));
        }
        return collOralHealthServices;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related OralHealthServices from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getOralHealthServices(Criteria criteria) throws TorqueException
    {
        if (collOralHealthServices == null)
        {
            if (isNew())
            {
               collOralHealthServices = new ArrayList();
            }
            else
            {
                      criteria.add(OralHealthServicePeer.STUDENTID, getStudentID() );
                      collOralHealthServices = OralHealthServicePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(OralHealthServicePeer.STUDENTID, getStudentID());
                      if (!lastOralHealthServicesCriteria.equals(criteria))
                {
                    collOralHealthServices = OralHealthServicePeer.doSelect(criteria);
                }
            }
        }
        lastOralHealthServicesCriteria = criteria;

        return collOralHealthServices;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getOralHealthServices(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getOralHealthServices(Connection con) throws TorqueException
    {
        if (collOralHealthServices == null)
        {
            collOralHealthServices = getOralHealthServices(new Criteria(10), con);
        }
        return collOralHealthServices;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related OralHealthServices from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getOralHealthServices(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collOralHealthServices == null)
        {
            if (isNew())
            {
               collOralHealthServices = new ArrayList();
            }
            else
            {
                       criteria.add(OralHealthServicePeer.STUDENTID, getStudentID());
                       collOralHealthServices = OralHealthServicePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(OralHealthServicePeer.STUDENTID, getStudentID());
                       if (!lastOralHealthServicesCriteria.equals(criteria))
                 {
                     collOralHealthServices = OralHealthServicePeer.doSelect(criteria, con);
                 }
             }
         }
         lastOralHealthServicesCriteria = criteria;

         return collOralHealthServices;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student is new, it will return
     * an empty collection; or if this Student has previously
     * been saved, it will retrieve related OralHealthServices from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Student.
     */
    protected List getOralHealthServicesJoinStudent(Criteria criteria)
        throws TorqueException
    {
        if (collOralHealthServices == null)
        {
            if (isNew())
            {
               collOralHealthServices = new ArrayList();
            }
            else
            {
                            criteria.add(OralHealthServicePeer.STUDENTID, getStudentID());
                            collOralHealthServices = OralHealthServicePeer.doSelectJoinStudent(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(OralHealthServicePeer.STUDENTID, getStudentID());
                        if (!lastOralHealthServicesCriteria.equals(criteria))
            {
                collOralHealthServices = OralHealthServicePeer.doSelectJoinStudent(criteria);
            }
        }
        lastOralHealthServicesCriteria = criteria;

        return collOralHealthServices;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collDmfxConds
     */
    protected List collDmfxConds;

    /**
     * Temporary storage of collDmfxConds to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initDmfxConds()
    {
        if (collDmfxConds == null)
        {
            collDmfxConds = new ArrayList();
        }
    }

    /**
     * Method called to associate a DmfxCond object to this object
     * through the DmfxCond foreign key attribute
     *
     * @param l DmfxCond
     * @throws TorqueException
     */
    public void addDmfxCond(DmfxCond l) throws TorqueException
    {
        getDmfxConds().add(l);
        l.setStudent((Student) this);
    }

    /**
     * The criteria used to select the current contents of collDmfxConds
     */
    private Criteria lastDmfxCondsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getDmfxConds(new Criteria())
     *
     * @throws TorqueException
     */
    public List getDmfxConds() throws TorqueException
    {
        if (collDmfxConds == null)
        {
            collDmfxConds = getDmfxConds(new Criteria(10));
        }
        return collDmfxConds;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related DmfxConds from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getDmfxConds(Criteria criteria) throws TorqueException
    {
        if (collDmfxConds == null)
        {
            if (isNew())
            {
               collDmfxConds = new ArrayList();
            }
            else
            {
                      criteria.add(DmfxCondPeer.STUDENTID, getStudentID() );
                      collDmfxConds = DmfxCondPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(DmfxCondPeer.STUDENTID, getStudentID());
                      if (!lastDmfxCondsCriteria.equals(criteria))
                {
                    collDmfxConds = DmfxCondPeer.doSelect(criteria);
                }
            }
        }
        lastDmfxCondsCriteria = criteria;

        return collDmfxConds;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getDmfxConds(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getDmfxConds(Connection con) throws TorqueException
    {
        if (collDmfxConds == null)
        {
            collDmfxConds = getDmfxConds(new Criteria(10), con);
        }
        return collDmfxConds;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related DmfxConds from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getDmfxConds(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collDmfxConds == null)
        {
            if (isNew())
            {
               collDmfxConds = new ArrayList();
            }
            else
            {
                       criteria.add(DmfxCondPeer.STUDENTID, getStudentID());
                       collDmfxConds = DmfxCondPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(DmfxCondPeer.STUDENTID, getStudentID());
                       if (!lastDmfxCondsCriteria.equals(criteria))
                 {
                     collDmfxConds = DmfxCondPeer.doSelect(criteria, con);
                 }
             }
         }
         lastDmfxCondsCriteria = criteria;

         return collDmfxConds;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student is new, it will return
     * an empty collection; or if this Student has previously
     * been saved, it will retrieve related DmfxConds from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Student.
     */
    protected List getDmfxCondsJoinStudent(Criteria criteria)
        throws TorqueException
    {
        if (collDmfxConds == null)
        {
            if (isNew())
            {
               collDmfxConds = new ArrayList();
            }
            else
            {
                            criteria.add(DmfxCondPeer.STUDENTID, getStudentID());
                            collDmfxConds = DmfxCondPeer.doSelectJoinStudent(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(DmfxCondPeer.STUDENTID, getStudentID());
                        if (!lastDmfxCondsCriteria.equals(criteria))
            {
                collDmfxConds = DmfxCondPeer.doSelectJoinStudent(criteria);
            }
        }
        lastDmfxCondsCriteria = criteria;

        return collDmfxConds;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collTotals
     */
    protected List collTotals;

    /**
     * Temporary storage of collTotals to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initTotals()
    {
        if (collTotals == null)
        {
            collTotals = new ArrayList();
        }
    }

    /**
     * Method called to associate a Total object to this object
     * through the Total foreign key attribute
     *
     * @param l Total
     * @throws TorqueException
     */
    public void addTotal(Total l) throws TorqueException
    {
        getTotals().add(l);
        l.setStudent((Student) this);
    }

    /**
     * The criteria used to select the current contents of collTotals
     */
    private Criteria lastTotalsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getTotals(new Criteria())
     *
     * @throws TorqueException
     */
    public List getTotals() throws TorqueException
    {
        if (collTotals == null)
        {
            collTotals = getTotals(new Criteria(10));
        }
        return collTotals;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related Totals from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getTotals(Criteria criteria) throws TorqueException
    {
        if (collTotals == null)
        {
            if (isNew())
            {
               collTotals = new ArrayList();
            }
            else
            {
                      criteria.add(TotalPeer.STUDENTID, getStudentID() );
                      collTotals = TotalPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(TotalPeer.STUDENTID, getStudentID());
                      if (!lastTotalsCriteria.equals(criteria))
                {
                    collTotals = TotalPeer.doSelect(criteria);
                }
            }
        }
        lastTotalsCriteria = criteria;

        return collTotals;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getTotals(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getTotals(Connection con) throws TorqueException
    {
        if (collTotals == null)
        {
            collTotals = getTotals(new Criteria(10), con);
        }
        return collTotals;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student has previously
     * been saved, it will retrieve related Totals from storage.
     * If this Student is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getTotals(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collTotals == null)
        {
            if (isNew())
            {
               collTotals = new ArrayList();
            }
            else
            {
                       criteria.add(TotalPeer.STUDENTID, getStudentID());
                       collTotals = TotalPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(TotalPeer.STUDENTID, getStudentID());
                       if (!lastTotalsCriteria.equals(criteria))
                 {
                     collTotals = TotalPeer.doSelect(criteria, con);
                 }
             }
         }
         lastTotalsCriteria = criteria;

         return collTotals;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Student is new, it will return
     * an empty collection; or if this Student has previously
     * been saved, it will retrieve related Totals from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Student.
     */
    protected List getTotalsJoinStudent(Criteria criteria)
        throws TorqueException
    {
        if (collTotals == null)
        {
            if (isNew())
            {
               collTotals = new ArrayList();
            }
            else
            {
                            criteria.add(TotalPeer.STUDENTID, getStudentID());
                            collTotals = TotalPeer.doSelectJoinStudent(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(TotalPeer.STUDENTID, getStudentID());
                        if (!lastTotalsCriteria.equals(criteria))
            {
                collTotals = TotalPeer.doSelectJoinStudent(criteria);
            }
        }
        lastTotalsCriteria = criteria;

        return collTotals;
    }
                            


          
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("StudentID");
              fieldNames.add("Surname");
              fieldNames.add("Firstname");
              fieldNames.add("Mi");
              fieldNames.add("Grade");
              fieldNames.add("Gender");
              fieldNames.add("Section");
              fieldNames.add("Birthmonth");
              fieldNames.add("Birthdate");
              fieldNames.add("Birthyear");
              fieldNames.add("Birthplace");
              fieldNames.add("Age");
              fieldNames.add("Address");
              fieldNames.add("Parent");
              fieldNames.add("Occupation");
              fieldNames.add("Medicalhist");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("StudentID"))
        {
                return new Integer(getStudentID());
            }
          if (name.equals("Surname"))
        {
                return getSurname();
            }
          if (name.equals("Firstname"))
        {
                return getFirstname();
            }
          if (name.equals("Mi"))
        {
                return getMi();
            }
          if (name.equals("Grade"))
        {
                return getGrade();
            }
          if (name.equals("Gender"))
        {
                return getGender();
            }
          if (name.equals("Section"))
        {
                return getSection();
            }
          if (name.equals("Birthmonth"))
        {
                return getBirthmonth();
            }
          if (name.equals("Birthdate"))
        {
                return getBirthdate();
            }
          if (name.equals("Birthyear"))
        {
                return getBirthyear();
            }
          if (name.equals("Birthplace"))
        {
                return getBirthplace();
            }
          if (name.equals("Age"))
        {
                return new Integer(getAge());
            }
          if (name.equals("Address"))
        {
                return getAddress();
            }
          if (name.equals("Parent"))
        {
                return getParent();
            }
          if (name.equals("Occupation"))
        {
                return getOccupation();
            }
          if (name.equals("Medicalhist"))
        {
                return getMedicalhist();
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(StudentPeer.STUDENTID))
        {
                return new Integer(getStudentID());
            }
          if (name.equals(StudentPeer.SURNAME))
        {
                return getSurname();
            }
          if (name.equals(StudentPeer.FIRSTNAME))
        {
                return getFirstname();
            }
          if (name.equals(StudentPeer.MI))
        {
                return getMi();
            }
          if (name.equals(StudentPeer.GRADE))
        {
                return getGrade();
            }
          if (name.equals(StudentPeer.GENDER))
        {
                return getGender();
            }
          if (name.equals(StudentPeer.SECTION))
        {
                return getSection();
            }
          if (name.equals(StudentPeer.BIRTHMONTH))
        {
                return getBirthmonth();
            }
          if (name.equals(StudentPeer.BIRTHDATE))
        {
                return getBirthdate();
            }
          if (name.equals(StudentPeer.BIRTHYEAR))
        {
                return getBirthyear();
            }
          if (name.equals(StudentPeer.BIRTHPLACE))
        {
                return getBirthplace();
            }
          if (name.equals(StudentPeer.AGE))
        {
                return new Integer(getAge());
            }
          if (name.equals(StudentPeer.ADDRESS))
        {
                return getAddress();
            }
          if (name.equals(StudentPeer.PARENT))
        {
                return getParent();
            }
          if (name.equals(StudentPeer.OCCUPATION))
        {
                return getOccupation();
            }
          if (name.equals(StudentPeer.MEDICALHIST))
        {
                return getMedicalhist();
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getStudentID());
            }
              if (pos == 1)
        {
                return getSurname();
            }
              if (pos == 2)
        {
                return getFirstname();
            }
              if (pos == 3)
        {
                return getMi();
            }
              if (pos == 4)
        {
                return getGrade();
            }
              if (pos == 5)
        {
                return getGender();
            }
              if (pos == 6)
        {
                return getSection();
            }
              if (pos == 7)
        {
                return getBirthmonth();
            }
              if (pos == 8)
        {
                return getBirthdate();
            }
              if (pos == 9)
        {
                return getBirthyear();
            }
              if (pos == 10)
        {
                return getBirthplace();
            }
              if (pos == 11)
        {
                return new Integer(getAge());
            }
              if (pos == 12)
        {
                return getAddress();
            }
              if (pos == 13)
        {
                return getParent();
            }
              if (pos == 14)
        {
                return getOccupation();
            }
              if (pos == 15)
        {
                return getMedicalhist();
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(StudentPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    StudentPeer.doInsert((Student) this, con);
                    setNew(false);
                }
                else
                {
                    StudentPeer.doUpdate((Student) this, con);
                }
            }

                                      
                
            if (collInitialHealthConds != null)
            {
                for (int i = 0; i < collInitialHealthConds.size(); i++)
                {
                    ((InitialHealthCond) collInitialHealthConds.get(i)).save(con);
                }
            }
                                          
                
            if (collOralHealthServices != null)
            {
                for (int i = 0; i < collOralHealthServices.size(); i++)
                {
                    ((OralHealthService) collOralHealthServices.get(i)).save(con);
                }
            }
                                          
                
            if (collDmfxConds != null)
            {
                for (int i = 0; i < collDmfxConds.size(); i++)
                {
                    ((DmfxCond) collDmfxConds.get(i)).save(con);
                }
            }
                                          
                
            if (collTotals != null)
            {
                for (int i = 0; i < collTotals.size(); i++)
                {
                    ((Total) collTotals.get(i)).save(con);
                }
            }
                          alreadyInSave = false;
        }
      }


                          
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  studentID ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setStudentID(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setStudentID(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getStudentID());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public Student copy() throws TorqueException
    {
        return copyInto(new Student());
    }
  
    protected Student copyInto(Student copyObj) throws TorqueException
    {
          copyObj.setStudentID(studentID);
          copyObj.setSurname(surname);
          copyObj.setFirstname(firstname);
          copyObj.setMi(mi);
          copyObj.setGrade(grade);
          copyObj.setGender(gender);
          copyObj.setSection(section);
          copyObj.setBirthmonth(birthmonth);
          copyObj.setBirthdate(birthdate);
          copyObj.setBirthyear(birthyear);
          copyObj.setBirthplace(birthplace);
          copyObj.setAge(age);
          copyObj.setAddress(address);
          copyObj.setParent(parent);
          copyObj.setOccupation(occupation);
          copyObj.setMedicalhist(medicalhist);
  
                    copyObj.setStudentID(0);
                                                                                                      
                                      
                
        List v = getInitialHealthConds();
        for (int i = 0; i < v.size(); i++)
        {
            InitialHealthCond obj = (InitialHealthCond) v.get(i);
            copyObj.addInitialHealthCond(obj.copy());
        }
                                                  
                
        v = getOralHealthServices();
        for (int i = 0; i < v.size(); i++)
        {
            OralHealthService obj = (OralHealthService) v.get(i);
            copyObj.addOralHealthService(obj.copy());
        }
                                                  
                
        v = getDmfxConds();
        for (int i = 0; i < v.size(); i++)
        {
            DmfxCond obj = (DmfxCond) v.get(i);
            copyObj.addDmfxCond(obj.copy());
        }
                                                  
                
        v = getTotals();
        for (int i = 0; i < v.size(); i++)
        {
            Total obj = (Total) v.get(i);
            copyObj.addTotal(obj.copy());
        }
                    
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public StudentPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Student:\n");
        str.append("StudentID = ")
           .append(getStudentID())
           .append("\n");
        str.append("Surname = ")
           .append(getSurname())
           .append("\n");
        str.append("Firstname = ")
           .append(getFirstname())
           .append("\n");
        str.append("Mi = ")
           .append(getMi())
           .append("\n");
        str.append("Grade = ")
           .append(getGrade())
           .append("\n");
        str.append("Gender = ")
           .append(getGender())
           .append("\n");
        str.append("Section = ")
           .append(getSection())
           .append("\n");
        str.append("Birthmonth = ")
           .append(getBirthmonth())
           .append("\n");
        str.append("Birthdate = ")
           .append(getBirthdate())
           .append("\n");
        str.append("Birthyear = ")
           .append(getBirthyear())
           .append("\n");
        str.append("Birthplace = ")
           .append(getBirthplace())
           .append("\n");
        str.append("Age = ")
           .append(getAge())
           .append("\n");
        str.append("Address = ")
           .append(getAddress())
           .append("\n");
        str.append("Parent = ")
           .append(getParent())
           .append("\n");
        str.append("Occupation = ")
           .append(getOccupation())
           .append("\n");
        str.append("Medicalhist = ")
           .append(getMedicalhist())
           .append("\n");
        return(str.toString());
    }
}
